home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-28 | 5.4 KB | 147 lines | [TEXT/MPS ] |
- MACHINE MC68020
- MC68881
- ;-------------------------------------------------
- Mxmpy PROC EXPORT
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Performs the matrix multiplication C = A * B.
- ;
- ; Calling sequence (FORTRAN):
- ; CALL MXMPY (A, B, C, L, M, N)
- ;
- ; where
- ; A is an array with L rows and M columns
- ; B is an array with M rows and N columns
- ; C is an array with L rows and N columns
- ; L, M, and N are INTEGERs.
- ;
- ; NOTE: All arrays must be completely filled,
- ; with no gaps. Do not try to pass part of an
- ; array unless it forms a contiguous block of
- ; memory locations.
- ;
- ; April 1990
- ; Jon Bell, Dept. of Physics & Computer Science
- ; Presbyterian College, Clinton SC 29325
- ;
- ; Written for MPW Assembler, v3.0.
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Locations of arguments to the subroutine,
- ; relative to the address stored in register A6.
- a EQU 28 ; addr. of a
- b EQU 24 ; addr. of b
- c EQU 20 ; addr. of c
- l EQU 16 ; addr. of # rows in a
- m EQU 12 ; addr. of # cols in a
- n EQU 8 ; addr. of # cols in b
- ; Locations of local variables, relative to the
- ; address stored in register A6.
- termCount EQU -4 ; initial value of term index
- rowCount EQU -8 ; initial value of col. index
- aColSize EQU -12 ; # of bytes per column of a
- bColSize EQU -16 ; # of bytes per column of b
- ; Other constants.
- ParamSize EQU 24 ; # of bytes of parameters
- LocalSize EQU -16 ; # of bytes of local var's
- zero EQU $0F ; 68882 code for constant 0
- ; Register usage.
- aPtr EQU A2 ; pointer into a
- bPtr EQU A3 ; pointer into b
- cPtr EQU A4 ; pointer into c
- rowIndex EQU D3 ; row-loop index
- colIndex EQU D4 ; column-loop index
- termIndex EQU D5 ; term-loop index
- aRowBase EQU D6 ; start of current row in a
- bColBase EQU D7 ; start of current col. in b
- term EQU FP0 ; one term for an elem. of c
- sum EQU FP1 ; sum for an element of c
- ;- - - - - - - - - - - - - - - - - - - - - - - - -
- ; Set up the stack frame, and save registers on
- ; the stack.
- LINK A6, #LocalSize
- MOVEM.L A2-A4/D3-D7, -(SP)
- ; Calculate and save the length of
- ; one column of a.
- MOVE.L l(A6), A0
- MOVE.L (A0), D0 ; # of rows
- MULU #12, D0 ; bytes per column
- MOVE.L D0, aColSize(A6)
- ; Calculate and save the length of
- ; one column of b.
- MOVE.L m(A6), A0
- MOVE.L (A0), D0 ; # of rows
- MULU #12, D0 ; bytes per column
- MOVE.L D0, bColSize(A6)
- ; Save the initial value of the term index.
- MOVE.L m(A6), A0
- MOVE.L (A0), termCount(A6)
- ; Save the initial value of the row index.
- MOVE.L l(A6), A0
- MOVE.L (A0), rowCount(A6)
- ; Initialize the column index.
- MOVE.L n(A6), A0
- MOVE.L (A0), colIndex
- ; Initialize the base address of the current
- ; column in b to the start of b.
- MOVE.L b(A6), bColBase
- ; Initialize the pointer into c.
- MOVE.L c(A6), cPtr
- BeginColLoop ; Cycle over the columns of c.
- SUBQ.L #1, colIndex
- BMI.S EndColLoop
- ; Initialize the row index.
- MOVE.L rowCount(A6), rowIndex
- ; Initialize the base address of the
- ; current row in a to the start of a.
- MOVE.L a(A6), aRowBase
- BeginRowLoop ; Cycle over the rows of c.
- SUBQ.L #1, rowIndex
- BMI.S EndRowLoop
- ; Initialize the a and b pointers
- ; for the next sum of terms.
- MOVE.L aRowBase, aPtr
- MOVE.L bColBase, bPtr
- ; Initialize the sum.
- FMOVECR.X #zero, sum
- ; Initialize the term index.
- MOVE.L termCount(A6), termIndex
- BeginTermLoop ; Cycle over the terms
- ; in the sum.
- SUBQ.L #1, termIndex
- BMI.S EndTermLoop
- ; Multiply the current element
- ; of b by the current element
- ; of a, and advance to the
- ; next element in the current
- ; column of b.
- FMOVE.X (bPtr)+, term
- FMUL.X (aPtr), term
- ; Add the new term to the sum.
- FADD.X term, sum
- ; Advance to the next element
- ; in the current row of a.
- ADDA.L aColSize(A6), aPtr
- BRA.S BeginTermLoop
- EndTermLoop
- ; Move the sum into the current
- ; element of c, and advance to the
- ; next row in the current
- ; column of c.
- FMOVE.X sum, (cPtr)+
- ; Advance to the next row in the
- ; current column of a.
- ADD.L #12, aRowBase
- BRA.S BeginRowLoop
- EndRowLoop
- ; Advance to next column in b.
- ADD.L bColSize(A6), bColBase
- BRA.S BeginColLoop
- EndColLoop
- ; All done. Restore the saved registers,
- ; clean up the stack and return.
- MOVEM.L (SP)+, A2-A4/D3-D7
- UNLK A6
- RTD #ParamSize
- DC.B 'MXMPY ' ; label for debugger
- ENDPROC
- END
-